<?php

/**
 * Created by PhpStorm.
 * User: 4399-0661
 * Date: 15-3-21
 * Time: 下午3:16
 */
class LibFactory
{
    /**
     * 数据库连接的工厂类
     * @param $key
     * @return \Library\database\LibBase
     */
    static function database($key = "")
    {
        $config = \LibConfig::readDB($key);
        if (empty($config)) {
            return false;
        }
        $driver = $config['DRIVER'] ?: 'mysqli';
        $class = '\Library\database\Lib' . ucfirst($driver);
        if (!class_exists($class)) {
            \LibLog::toDb("数据库连接类型错误,{$driver}不存在", "global", "db");
            return false;
        }
        $db = new $class($key);
        return $db;
    }

    static function cache($key, $type = 'redis')
    {
        $method = 'read' . ucfirst($type);
        if (!method_exists('\LibConfig', $method)) {
            \LibLog::toDb("缓存读取方法{$method}不存在", "global", "db");
            return false;
        }
        $config = \LibConfig::$method($key);
    }
} 